// ============================== 导入依赖 ============================== //

import CORE from '@/CORE'

// ============================== 导出工具 ============================== //

export default {
  /**
   * 设置路径名称的映射
   *
   * @param {Object} namesMap 路径名称的映射
   * @param {Array} tree 原始结构树
   * @param {Array} field 字段列表
   * @param {Array} nameList ID 列表
   */
  setNamesMap(namesMap, tree, field, nameList = []) {
    const { children, id, label } = field
    tree.forEach((item) => {
      const newNameList = [...nameList, item[label]]
      namesMap[item[id]] = newNameList.join('->')
      if (CORE.isArray(item[children])) this.setNamesMap(namesMap, item[children], field, newNameList)
    })
  },
}
